<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Demo</title>
    </head>
    <body></body>
    <script>
        //链式操作
        class Demo {
            constructor(executor) {
                executor()
            }
            then(onResolve, onReject) {
                onReject('a')
                return new Demo(() => {})
            }
        }

        new Demo((resolve, reject) => {})
            .then(
                v => console.log(v),
                r => console.log(r)
            )
            .then(
                v => console.log(v),
                r => console.log(r)
            )
            .then(
                v => console.log(v),
                r => console.log(r)
            )
            .then(
                v => console.log(v),
                r => console.log(r)
            )

        // new Promise((resolve, reject) => {
        //     resolve('ok')
        // })
        //     .then(
        //         v => {
        //             console.log(v)
        //             return 'p'
        //         },
        //         r => console.log(r)
        //     )
        //     .then(
        //         v => console.log(v),
        //         r => console.log(r)
        //     )
        // console.log(new Demo().then().then())
    </script>
</html>
